import React, { PureComponent } from 'react'

import { Carousel } from 'antd-mobile'
import http from 'utils/http'
export default class Swiper extends PureComponent {
    state = {
        swiperList :[]
    }
    render() {
        return (
           this.state.swiperList.length>0 &&(<Carousel className="my-carousel"
                dots={true}
                dragging={true}
                swiping={true}
                autoplay
                infinite
            > 
              {
                  this.state.swiperList.map((value,index)=>(
                      <div key={value.id} >
                          <img src={value.img} alt=""/>
                      </div>
                  ))
              }
          </Carousel>
        ))
    }
   async componentDidMount(){
        // fetch('/api/swiper')
        // .then(respose=>respose.json())
        // .then(result=>{
        //     // console.log(result)
          
        //     this.setState({
        //         swiperList:result.data.slice(0,5)   //只取前5个数据
        //     })
        //     // console.log(result.data.slice(0,5))
        // })

       let result =await http.get({url:'/api/swiper'})
            this.setState({
                swiperList:result.data.slice(0,5)   //只取前5个数据
            })
    }
    
}  
